/*
Copyright (C) 2011  Christoph Schnack, Berlin (Germany)

This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.
*/
package VMAddManyWords;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

import javax.swing.*;

import GuiTools.*;
import Settings.*;
import Storage.*;
import VocabularyManagement.MeaningFormularPanel;

/**
 * @author Christoph Schnack
 *
 */
public class WordRowSimple extends MeaningFormularPanel {
	TermPanel meaningPanel;
	Vector<Term> synonyms = new Vector<Term>();
	String phonetic = "",errorTxt="";
	MetaPanel metaPanel;
	Vector<String> categories;
	JPanel rowPanel;
	TermClass termClass;
	Settings SET;
	Language LANG;
	TribuitFrame parentFrame;
	
	
	public WordRowSimple(TribuitFrame parentFrameArg, Settings setArg,TermClass tcArg, Vector<String> categoriesArg){
		super();
		termClass = tcArg;
		rowPanel = this;
		categories = categoriesArg;
		parentFrame = parentFrameArg;
		SET = setArg;
		LANG = SET.getLanguage();
		buildGUI();
	}
	
	public void buildGUI(){
		meaningPanel = new TermPanel(SET,termClass,categories,"");
		meaningPanel.setOpaque(false);
		metaPanel = new MetaPanel(SET,termClass);
		metaPanel.setOpaque(false);
		
		JButton editSynonymsBtn = new JButton(LANG.getEdit());
		editSynonymsBtn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				EditSynonymsDialog esd = new EditSynonymsDialog(parentFrame,SET,termClass,categories,synonyms);
				if(!esd.getAborted()){
					synonyms = esd.getResult();
				}
			}
		});
		JButton editPhoneticBtn = new JButton(LANG.getEdit());
		editPhoneticBtn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				EditPhoneticDialog epd = new EditPhoneticDialog(parentFrame,SET,phonetic);
				if(!epd.getAborted()){
					phonetic = epd.getResult();
				}
			}
		});
		
		LabelPanel synonymsLP = new LabelPanel(LANG.getSynonyms(),editSynonymsBtn);
		synonymsLP.setAllOpaque(false);
		LabelPanel phoneticLP = new LabelPanel(LANG.getPhonetic(),editPhoneticBtn);
		phoneticLP.setAllOpaque(false);
		
		this.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.gridx = GridBagConstraints.REMAINDER; 
		gbc.anchor = GridBagConstraints.NORTHWEST;
		this.add(meaningPanel,gbc);
		this.add(metaPanel,gbc);
		this.add(synonymsLP,gbc);
		this.add(phoneticLP,gbc);
		this.setOpaque(false);
	}
	
	public void setTermClass(TermClass tc, String name){
		termClass = tc;
		meaningPanel.setTermClass(termClass);
		if(synonyms.size()>0){
			for(Term t : synonyms){
				if(termClass.hasPrefix()){
					if(termClass.getPreFixVal()!=null) t.setArticle(termClass.getPreFixVal().firstElement());
				}
				else{
					t.setArticle("");
				}
			}
		}
		metaPanel.setTermClass(termClass);
	}
	
	//FIXME note and example sentence
	public void clearAll(){
		meaningPanel.resetAllData();
		metaPanel.resetAllFields();
		synonyms.clear();
		phonetic = "~";
	}
	
	public void grabFocusFirstTF(){
		meaningPanel.mark();
	}

	public void setUpMeaning(Meaning m) {
		
	}

	public void setMeaningTFTitle(String txt) {
		
	}

	public Meaning getMeaning() {
		return null;
	}

	public String getErrorMessage() {
		return errorTxt;
	}

	public boolean checkInputs() {
		return false;
	}

	public void resetAllInputs() {
		// TODO Auto-generated method stub
		
	}
}
